<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitInviteRecord extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('invite_records', function (Blueprint $table) {

            $table->comment = '邀请记录表表';

            $table->increments('id');
            $table->uuid('uuid')->index();


            $table->integer('indirect_inviter_id')->nullable()->index()->comment('间接邀请人'); // 用户id 所得佣金

            $table->integer('direct_inviter_id')->index()->comment('邀请人'); // 用户id 所得佣金

            $table->integer('user_id')->index()->comment('被邀请人'); // 用户id 所得佣金


            $table->json('base_reward')->nullable()->comment('基本邀请奖励'); // 一级代理佣金
            $table->json('added_reward')->nullable()->comment('额外奖励'); // 一级代理佣金
            $table->integer('invite_index')->unsigned()->index()->comment('邀请的第几个人'); // 一级代理佣金

            $table->tinyInteger('invite_level')->unsigned()->default(0)->index()->comment('中间间隔人数 0为直接邀请 1为间接隔1人'); //

            $table->timestamp('invite_at')->nullable()->comment('邀请时间'); // 一级代理佣金

            $table->tinyInteger('status')->unsigned()->default(0)->index()->comment('待发放奖励  1为已发放奖励'); //

            $table->softDeletes();
            $table->timestamps();
        });

        Schema::table('users', function (Blueprint $table) {
            $table->integer('invite_reward_status')->default(0)->index()->comment('邀请奖励发放情况,0为未发放 1为已处理 2为无奖励'); // 用户id

            $table->renameColumn('invite_index', 'invite_total');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('invite_records');
    }
}
